package android.slc.appbase.ui.vd;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;

import java.util.List;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/8/13 9:29
 */
public interface ICommonlyShelfTabView {
    TabLayout getTabLayout();

    ViewPager2 getViewPager();

    default void loadTab() {
        Object host = getHostByTabLayoutViewDelegate();
        if (host instanceof FragmentActivity) {
            new TabLayoutViewDelegate(getTabLayout(),
                    getViewPager(),
                    (FragmentActivity) host,
                    getTabFragment(),
                    getTabTitle()).
                    attach();
        } else if (host instanceof Fragment) {
            new TabLayoutViewDelegate(getTabLayout(),
                    getViewPager(),
                    (Fragment) host,
                    getTabFragment(),
                    getTabTitle()).
                    attach();
        }
    }

    String[] getTabTitle();

    List<Fragment> getTabFragment();

    default Object getHostByTabLayoutViewDelegate(){
        return this;
    }
}
